home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / admin / dig-2.0 / dig-2 / dig.2.0 / options.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-04  |  7.7 KB  |  258 lines

  1.  
  2. /*
  3.  * Copyright (c) 1985 Regents of the University of California.
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms are permitted
  7.  * provided that this notice is preserved and that due credit is given
  8.  * to the University of California at Berkeley. The name of the University
  9.  * may not be used to endorse or promote products derived from this
  10.  * software without specific prior written permission. This software
  11.  * is provided ``as is'' without express or implied warranty.
  12.  */
  13.  
  14. /*
  15.  ***************************************************************************
  16.  *
  17.  *  SetOption -- 
  18.  *
  19.  *    This routine is used to change the state information
  20.  *    that affect the lookups. The command format is
  21.  *       set keyword[=value]
  22.  *    Most keywords can be abbreviated. Parsing is very simplistic--
  23.  *    A value must not be separated from its keyword by white space.
  24.  *
  25.  *      Andrew Cherenson        CS298-26  Fall 1985
  26.  *
  27.  ***************************************************************************
  28.  */
  29.  
  30. /*
  31. ** Modified for 'dig' version 2.0 from University of Southern
  32. ** California Information Sciences Institute (USC-ISI). 9/1/90
  33. */
  34.  
  35. int
  36. SetOption(string)
  37.     char *string;
  38. {
  39.     char     option[NAME_LEN];
  40.     char     type[NAME_LEN];
  41.     char     *ptr;
  42.     int     i;
  43.  
  44.     i = sscanf(string, " %s", option);
  45.     if (i != 1) {
  46.     fprintf(stderr, ";*** Invalid option: %s\n",  option);
  47.     return(ERROR);
  48.     } 
  49.    
  50.     if (strncmp(option, "aa", 2) == 0) {    /* aaonly */
  51.         _res.options |= RES_AAONLY;
  52.     } else if (strncmp(option, "noaa", 4) == 0) {
  53.         _res.options &= ~RES_AAONLY;
  54.     } else if (strncmp(option, "deb", 3) == 0) {    /* debug */
  55.         _res.options |= RES_DEBUG;
  56.     } else if (strncmp(option, "nodeb", 5) == 0) {
  57.         _res.options &= ~(RES_DEBUG | RES_DEBUG2);
  58.     } else if (strncmp(option, "ko", 2) == 0) {    /* keepopen */
  59.         _res.options |= (RES_STAYOPEN | RES_USEVC);
  60.     } else if (strncmp(option, "noko", 4) == 0) {
  61.         _res.options &= ~RES_STAYOPEN;
  62.     } else if (strncmp(option, "d2", 2) == 0) {    /* d2 (more debug) */
  63.         _res.options |= (RES_DEBUG | RES_DEBUG2);
  64.     } else if (strncmp(option, "nod2", 4) == 0) {
  65.         _res.options &= ~RES_DEBUG2;
  66.     } else if (strncmp(option, "def", 3) == 0) {    /* defname */
  67.         _res.options |= RES_DEFNAMES;
  68.     } else if (strncmp(option, "nodef", 5) == 0) {
  69.         _res.options &= ~RES_DEFNAMES;
  70.     } else if (strncmp(option, "sea", 3) == 0) {    /* search list */
  71.         _res.options |= RES_DNSRCH;
  72.     } else if (strncmp(option, "nosea", 5) == 0) {
  73.         _res.options &= ~RES_DNSRCH;
  74.     } else if (strncmp(option, "do", 2) == 0) {    /* domain */
  75.         ptr = index(option, '=');
  76.         if (ptr != NULL) {
  77.         sscanf(++ptr, "%s", _res.defdname);
  78.         res_re_init();
  79.         }
  80.       } else if (strncmp(option, "ti", 2) == 0) {      /* timeout */
  81.         ptr = index(option, '=');
  82.         if (ptr != NULL) {
  83.           sscanf(++ptr, "%d", &_res.retrans);
  84.         }
  85.  
  86.       } else if (strncmp(option, "ret", 3) == 0) {    /* retry */
  87.         ptr = index(option, '=');
  88.         if (ptr != NULL) {
  89.           sscanf(++ptr, "%d", &_res.retry);
  90.         }
  91.  
  92.     } else if (strncmp(option, "i", 1) == 0) {    /* ignore */
  93.         _res.options |= RES_IGNTC;
  94.     } else if (strncmp(option, "noi", 3) == 0) {
  95.         _res.options &= ~RES_IGNTC;
  96.     } else if (strncmp(option, "pr", 2) == 0) {    /* primary */
  97.         _res.options |= RES_PRIMARY;
  98.     } else if (strncmp(option, "nop", 3) == 0) {
  99.         _res.options &= ~RES_PRIMARY;
  100.     } else if (strncmp(option, "rec", 3) == 0) {    /* recurse */
  101.         _res.options |= RES_RECURSE;
  102.     } else if (strncmp(option, "norec", 5) == 0) {
  103.         _res.options &= ~RES_RECURSE;
  104.     } else if (strncmp(option, "v", 1) == 0) {    /* vc */
  105.         _res.options |= RES_USEVC;
  106.     } else if (strncmp(option, "nov", 3) == 0) {
  107.         _res.options &= ~RES_USEVC;
  108.     } else if (strncmp(option, "pfset", 5) == 0) {
  109.         ptr = index(option, '=');
  110.         if (ptr != NULL) {
  111.           pfcode = xstrtonum(++ptr);
  112.         }
  113.     } else if (strncmp(option, "pfand", 5) == 0) {
  114.         ptr = index(option, '=');
  115.         if (ptr != NULL) {
  116.           pfcode = pfcode & xstrtonum(++ptr);
  117.         }
  118.     } else if (strncmp(option, "pfor", 4) == 0) {
  119.         ptr = index(option, '=');
  120.         if (ptr != NULL) {
  121.           pfcode = pfcode | xstrtonum(++ptr);
  122.         }
  123.     } else if (strncmp(option, "pfmin", 5) == 0) {
  124.           pfcode = PRF_MIN;
  125.     } else if (strncmp(option, "pfdef", 5) == 0) {
  126.           pfcode = PRF_DEF;
  127.     } else if (strncmp(option, "an", 2) == 0) {  /* answer section */
  128.           pfcode |= PRF_ANS;
  129.     } else if (strncmp(option, "noan", 4) == 0) {
  130.           pfcode &= ~PRF_ANS;
  131.     } else if (strncmp(option, "qu", 2) == 0) {  /* question section */
  132.           pfcode |= PRF_QUES;
  133.     } else if (strncmp(option, "noqu", 4) == 0) {  
  134.           pfcode &= ~PRF_QUES;
  135.     } else if (strncmp(option, "au", 2) == 0) {  /* authority section */
  136.           pfcode |= PRF_AUTH;
  137.     } else if (strncmp(option, "noau", 4) == 0) {  
  138.           pfcode &= ~PRF_AUTH;
  139.     } else if (strncmp(option, "ad", 2) == 0) {  /* addition section */
  140.           pfcode |= PRF_ADD;
  141.     } else if (strncmp(option, "noad", 4) == 0) {  
  142.           pfcode &= ~PRF_ADD;
  143.     } else if (strncmp(option, "tt", 2) == 0) {  /* TTL & ID */
  144.           pfcode |= PRF_TTLID;
  145.     } else if (strncmp(option, "nott", 4) == 0) {  
  146.           pfcode &= ~PRF_TTLID;
  147.     } else if (strncmp(option, "he", 2) == 0) {  /* head flags stats */
  148.           pfcode |= PRF_HEAD2;
  149.     } else if (strncmp(option, "nohe", 4) == 0) {  
  150.           pfcode &= ~PRF_HEAD2;
  151.     } else if (strncmp(option, "H", 1) == 0) {  /* header all */
  152.           pfcode |= PRF_HEADX;
  153.     } else if (strncmp(option, "noH", 3) == 0) {  
  154.           pfcode &= ~(PRF_HEADX);
  155.     } else if (strncmp(option, "qr", 2) == 0) {  /* query */
  156.           pfcode |= PRF_QUERY;
  157.     } else if (strncmp(option, "noqr", 4) == 0) {  
  158.           pfcode &= ~PRF_QUERY;
  159.     } else if (strncmp(option, "rep", 3) == 0) {  /* reply */
  160.           pfcode |= PRF_REPLY;
  161.     } else if (strncmp(option, "norep", 5) == 0) {  
  162.           pfcode &= ~PRF_REPLY;
  163.     } else if (strncmp(option, "cm", 2) == 0) {  /* command line */
  164.           pfcode |= PRF_CMD;
  165.     } else if (strncmp(option, "nocm", 4) == 0) {  
  166.           pfcode &= ~PRF_CMD;
  167.     } else if (strncmp(option, "cl", 2) == 0) {  /* class mnemonic */
  168.           pfcode |= PRF_CLASS;
  169.     } else if (strncmp(option, "nocl", 4) == 0) {  
  170.           pfcode &= ~PRF_CLASS;
  171.     } else if (strncmp(option, "st", 2) == 0) {  /* stats*/
  172.           pfcode |= PRF_STATS;
  173.     } else if (strncmp(option, "nost", 4) == 0) {  
  174.           pfcode &= ~PRF_STATS;
  175.     } else if (strncmp(option, "sor", 3) == 0) {  /* sort */
  176.           pfcode |= PRF_SORT;
  177.     } else if (strncmp(option, "nosor", 5) == 0) {  
  178.           pfcode &= ~PRF_SORT;
  179.     } else {
  180.         fprintf(stderr, "; *** Invalid option: %s\n",  option);
  181.         return(ERROR);
  182.       }
  183.     return(SUCCESS);
  184. }
  185.  
  186.  
  187.  
  188. /*
  189.  * Fake a reinitialization when the domain is changed.
  190.  */
  191. res_re_init()
  192. {
  193.     register char *cp, **pp;
  194.     int n;
  195.  
  196.     /* find components of local domain that might be searched */
  197.     pp = _res.dnsrch;
  198.     *pp++ = _res.defdname;
  199.     for (cp = _res.defdname, n = 0; *cp; cp++)
  200.     if (*cp == '.')
  201.         n++;
  202.     cp = _res.defdname;
  203.     for (; n >= LOCALDOMAINPARTS && pp < _res.dnsrch + MAXDNSRCH; n--) {
  204.     cp = index(cp, '.');
  205.     *pp++ = ++cp;
  206.     }
  207.     *pp = 0;
  208.     _res.options |= RES_INIT;
  209. }
  210.  
  211.  
  212.  
  213. /*
  214. ** Written for 'dig' version 1.0 at University of Southern
  215. ** California Information Sciences Institute (USC-ISI). 3/27/89
  216. */
  217. /*
  218.  * convert char string (decimal, octal, or hex) to integer
  219.  */
  220. int xstrtonum(p)
  221. char *p;
  222. {
  223. int v = 0;
  224. int i;
  225. int b = 10;
  226. int flag = 0;
  227. while (*p != 0) {
  228.   if (!flag++)
  229.     if (*p == '0') {
  230.       b = 8; p++;
  231.       continue;
  232.     }
  233.   if (isupper(*p))
  234.       *p=tolower(*p);
  235.   if (*p == 'x') {
  236.     b = 16; p++;
  237.     continue;
  238.   }
  239.   if (isdigit(*p)) {
  240.     i = *p - '0';
  241.   } else if (isxdigit(*p)) {
  242.     i = *p - 'a' + 10;
  243.   } else {
  244.     fprintf(stderr,"; *** Bad char in numeric string -- ignored\n");
  245.     i = -1;
  246.   }
  247.   if (i >= b) {
  248.     fprintf(stderr,"; *** Bad char in numeric string -- ignored\n");
  249.     i = -1;
  250.   }
  251.   if (i >= 0)
  252.     v = v * b + i;
  253. p++;
  254. }
  255. return(v);
  256. }
  257.  
  258.